home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagn_r.zip / NUMBERS.SWG / 0031_Verify ISBN Numbers.pas < prev    next >
Pascal/Delphi Source File  |  1993-10-28  |  2KB  |  56 lines

  1. {===========================================================================
  2. Date: 09-22-93 (20:14)
  3. From: GREG VIGNEAULT
  4. Subj: Pascal ISBN verification
  5.  
  6.  Here's a snippet of TP code for the free SWAG archives. It verifies
  7.  ISBN numbers, via the embedded checksum ... }
  8.  
  9. (********************************************************************)
  10. (* Turbo/Quick/StonyBrook Pascal source file: ISBN.PAS  v1.0 GSV    *)
  11. (* Verify any International Standard Book Number (ISBN) ...         *)
  12.  
  13. PROGRAM checkISBN;
  14.  
  15. CONST TAB = #9;                       { ASCII horizontal tab         }
  16.       LF  = #10;                      { ASCII line feed              }
  17.  
  18. VAR ISBNstr : STRING[16];
  19.     loopc, ISBNlen, M, chksm : BYTE;
  20.  
  21. BEGIN {checkISBN}
  22.  
  23.   WriteLn (LF,TAB,'ISBN Check v1.0 Copyright 1993 Greg Vigneault',LF);
  24.  
  25.   IF ( ParamCount <> 1 ) THEN BEGIN   { we want just one input parm  }
  26.     WriteLn ( TAB, 'Usage: ISBN <ISBN#>', LF );
  27.     Halt(1);
  28.   END; {IF}
  29.  
  30.   ISBNstr := ParamStr (1);            { get the ISBN number          }
  31.   Write ( TAB, 'Checking ISBN# ', ISBNstr, ' ...' );
  32.   { eliminate any non-digit characters from the ISBN string...       }
  33.   ISBNlen := 0;
  34.   FOR loopc := 1 TO ORD ( ISBNstr[0] ) DO
  35.     IF ( ISBNstr[ loopc ] IN ['0'..'9'] ) THEN BEGIN
  36.       INC ( ISBNlen );
  37.       ISBNstr[ ISBNlen ] := ISBNstr[ loopc ];
  38.   END; {IF & FOR}
  39.   { an 'X' at the end of the ISBN affects the result...              }
  40.   IF ( ISBNstr[ ORD ( ISBNstr[0] ) ] IN ['X','x'] ) THEN
  41.     M := 10
  42.   ELSE
  43.     M := ORD ( ISBNstr[ ISBNlen ] ) - 48;
  44.   ISBNstr[0] := CHR ( ISBNlen );          { new ISBN string length   }
  45.   WriteLn ( 'reduced ISBN = ', ISBNstr );  WriteLn;
  46.   chksm := 0;                             { initialize checksum      }
  47.   FOR loopc := 1 TO ISBNlen-1 DO
  48.     INC (chksm, ( ORD ( ISBNstr[ loopc ] ) - 48 ) * loopc );
  49.   Write ( TAB, 'ISBN ' );
  50.   IF ( ( chksm MOD 11 ) = M ) THEN
  51.     WriteLn ( 'is okay.' )
  52.   ELSE
  53.     WriteLn ( 'error!',#7 );
  54.  
  55. END {checkISBN}.                      (* Not for commercial retail. *)
  56.